#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <unistd.h>
#include <stdlib.h>
#include <crypt.h>

using namespace std;

int main()
{
	string string1,string2;
	map<string, string> dict;
	map<string, string>::iterator it;
	ifstream inf;

	inf.open("/usr/share/lib/dict/words");
	char *string_temp1,*string_temp2;
	string_temp1 = (char *)malloc(sizeof(char)*128);
	string_temp2 = (char *)malloc(sizeof(char)*128);
	
	while(!inf.eof())
	{
		inf.getline(string_temp1,128);
		string1 = string(string_temp1);
		string_temp2=crypt(string_temp1,"AB");
		string2 = string(string_temp2);
//		cout << "mima:" << string2 << endl;
		dict[string1] = string2;
//		cout << string1<<endl;
	}
	free(string_temp1);
	free(string_temp2);
	inf.close();

	ifstream crypted;
	crypted.open("./simplepasswd");
	string string_temp;
	unsigned position;
	while(!crypted.eof())
	{
		getline(crypted, string_temp);

		//cout << string_temp;
		position = string_temp.find(":AB:");
		if (position >= string_temp.length())
			continue;

//		cout << position << "  "<< string_temp.length() <<" "<< endl;
		string temp = string_temp.substr(position+4);
//		cout << temp << endl;
		temp = "AB"+temp;
		string account = string_temp.substr(0,position);
		for (it = dict.begin() ; it != dict.end() ; it++)
		{
			
			if(it->second == string(temp))
			{
				cout << "account: " << account;
				cout << " clearpassword: " << it->first<<endl;
				break;
			}
		}
	}
	crypted.close();
	return 0;
}

